package com.youmu.sichuansfc.dao.impl;

import com.youmu.sichuansfc.dao.FundManagerStaffDao;
import com.youmu.sichuansfc.domain.YoumuFundManagerStaff;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * @author WYZ
 * @create 2018-01-30 18:29
 * @desc
 **/
@Repository
public class FundManagerStaffDaoImpl  implements FundManagerStaffDao {

    private EntityManager em;
    @PersistenceContext
    public void setEm(EntityManager em) {
        this.em = em;
    }

    @Override
    public YoumuFundManagerStaff upload(YoumuFundManagerStaff youmuFundManagerStaff) {

        if (youmuFundManagerStaff.getId() != null){
            em.merge(youmuFundManagerStaff);
        }else {
            em.persist(youmuFundManagerStaff);
        }
        return youmuFundManagerStaff;
    }

    @Override
    public List<YoumuFundManagerStaff> findByFundManagerId(long fundManagerId) {
        String sql  = "from YoumuFundManagerStaff where is_delete = 0 and fund_manager_id =:fundManagerId";

        return em.createQuery(sql, YoumuFundManagerStaff.class)
                .setParameter("fundManagerId", fundManagerId)
                .getResultList();
    }
}
